package TrainModel;

import org.junit.Test;
import static org.junit.Assert.*;

import Utilities.Message;
import Utilities.logFileIO;

public class CommModuleUnitTests
{
	private logFileIO utLogFile;
	
	public CommModuleUnitTests()
	{
		// Init log file writer
		utLogFile = new logFileIO( "CommMod_UnitTest_LogFile", "txt" );
	}

	@Test
	// Test that normal message passing works
	public void signalPickupSuccessful()
	{
		CommunicationModule cm = new CommunicationModule(utLogFile, 0);
		
		Message m1 = new Message("Hello!");
		
		cm.recieveMessage(m1);
		
		Message m2 =  cm.getMessage();
		
		assertTrue( (m2.sMessage1).equals("Hello!") );
	}
	
	@Test
	// Test that setting a signal pickup failure causes messages to be null
	public void signalPickupFailure()
	{
		CommunicationModule cm = new CommunicationModule(utLogFile, 0);
		
		
		cm.setSignalPickupFailure(true);
		
		Message m1 = new Message("Hello!");
		
		cm.recieveMessage(m1);
		
		Message m2 =  cm.getMessage();
		
		assertTrue( m2 == null );
	}
	
	@Test
	// Test that repairing signal pickup failure restores normal operations
	public void signalPickupRepair()
	{
		CommunicationModule cm = new CommunicationModule(utLogFile, 0);
		Message m1 = new Message("Hello!");
		
		cm.setSignalPickupFailure(true);
		cm.recieveMessage(m1);

		cm.setSignalPickupFailure(false);
		cm.recieveMessage(m1);
		
		Message m2 =  cm.getMessage();
		
		assertTrue( (m2.sMessage1).equals("Hello!") );
	}

}
